<html>
<head>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <!-- font -->
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>

    <script src="${ctx}/layui/layui.all.js"></script>

    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
    <script src="${ctx}/js/util.js"></script>
</head>
<style>
    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }
</style>
<body>
<div class="modal fade" id="loadingModal">
    <div style="width: 200px;height:20px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px">
        <div class="progress progress-striped active" style="margin-bottom: 0;">
            <div class="progress-bar" style="width: 100%;"></div>
        </div>
        <font color="black" size="10">正在处理中请耐心等待...</font>
    </div>
</div>
<div class="container-fluid">
    <div id="toolbar">
    </div>
    <form class="layui-form" action="" style="margin-top: 10px">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 95px">起始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="star" placeholder="请选择时间">
            </div>
        </div>
        <div class="layui-inline">
        <label class="layui-form-label" style="width: 95px">结束时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="end" placeholder="请选择时间">
        </div>
        <span id="search_btn" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">查询</span>
</div>

</form>
<table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
       lay-filter="tableFilter">

</table>
</div>

<script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
<script src="${ctx}/js/extends.js"></script>
<script type="text/html" id="barDemo">

    {{#  if(d.remittance == 1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="jujue">拒绝</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="rgzz">人工转账</a>
    {{#  if(d.method == 1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="zfb">支付宝一键转账</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="wx">微信一键转账</a>
    {{#  } }}
    {{#  } else { }}
    {{#  } }}
    <a class="layui-btn layui-btn-xs " lay-event="xbls">新版流水</a>
    <a class="layui-btn layui-btn-xs " lay-event="lsjl">流水</a>
    <a class="layui-btn layui-btn-xs " lay-event="rwjl">任务记录</a>
</script>
<script>
    var cashstr="${cash_str}";
    var star = "";
    var end = "";
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'

        });
    });
    layui.use('table', function () {
        tableIns = layui.table;
        form = layui.form;
        tableIns.render({
            elem: '#layTable'

            ,
            url: '/applies/staff-getList'
            ,
            toolbar: true
            ,
            method: 'POST'

            ,
            id: 'dataTableId'
            ,
            where: {
                checkStatus: 2
                , status: 'Empty'
            }
            ,
            cols: [[
                {
                    type: 'checkbox', field: 'id'
                }

                , {
                    field: 'createTime',
                    title: '提现时间',
                    width: 100,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        return dateFormat(data.createTime);
                    }
                }
                //, {field: 'realname', title: '真实姓名', width: 100, align: 'center', sort: true}
                , {
                    field: 'amount',
                    title: '申请提现(元)',
                    width: 160,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        return (data.amount / 100) + '元';
                    }
                }
                , {
                    field: 'method', title: '提现方式', width: 100, align: 'center', sort: true,
                    templet: function (data) {
                        if (data.method == 1) {
                            return "<div style='color: blue'>支付宝<div> ";
                        } else {
                            return "<div style='color: red'>微信<div> ";
                        }

                    }
                }
                , {
                    field: 'phone', title: '手机号', width: 120, align: 'center', sort: true,
                    templet: function (data) {
                        var str = data.phone;
                        if (data.sta === 'Unusual') {
                            str += '<i class="layui-icon" style="color: red">&#xe66c;</i>';
                        }
                        return str;
                    }
                }
                , {
                    field: 'content', title: '支付宝', width: 160, align: 'center', sort: true,
                    templet: function (data) {

                        var value = data.content;
                        if(value===undefined){
                            return '';
                        }
                        value = JSON.parse(value);
                        if (data.amount > 1000) {
                            return (value['alipay'] + ':' + value['alipayname']);
                        } else {
                            return '<span style="color:red">' + (value['alipay'] + ':' + value['alipayname']) + '</span>';
                        }
                    }
                }
                , {
                    field: 'totalAmount',
                    title: '用户总收益(元)',
                    width: 160,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        var value = data.totalAmount;
                        value = value / 100;
                        var a = '<a onClick="details(\'' + data.memberId + '\')">' + value + '元</a>';
                        return a;
                    }
                }
                , {
                    field: 'oldAmount',
                    title: '历史提现(元)',
                    width: 160,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        return (data.oldAmount / 100) + '元';
                    }
                }
                , {
                    field: 'create_by',
                    title: '账户余额',
                    width: 160,
                    align: 'center',
                    sort: true,
                    templet: function (row) {
                        var a = row.totalAmount - row.oldAmount;
                        return (a / 100) + '元';
                    }
                }

                , {
                    field: 'extra',
                    title: '额外奖励(元)',
                    width: 160,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        return (data.extra / 100) + '元';
                    }
                }
                , {
                    field: 'c', title: '累计提现次数（成功/失败）', width: 160, align: 'center', templet: function (data) {

                        var str = '<font style="color: green">' + data.successcount + '/</font>';
                        str += '<font style="color: red">' + data.failcount + '</font>';
                        return str;
                    }
                }

                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 360, align: 'center'}
            ]]
            ,
            page: true
        });
        $("#search_btn").click(function () {
            reload();

        });

        form.on('switch(sexDemo)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, 'False');
            } else {
                commonenable(this.value, 'true');
            }

        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });
        // 流水
        var xbls = function (memberId) {
            var id = 'xbls'+memberId;
            var title = '收支明细';
            var href = '/sys/membernewtrade/list?memberId=' + memberId;
            if (id) {
                window.parent.iw.dialog({
                    size: 'lg',
                    id: id,
                    title: title,
                    href: href
                });
            }
        };
        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/delete/data",
                    type: 'post',
                    data: {"table": table, "ids": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                if (data.has_deleted === 1) {
                    layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                    return;
                }
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                if (data.has_deleted === 1) {
                    layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                    return;
                }
                layer_show("修改", "/financeRecord/edit?id=" + data.id, "550", "650");
                parent.search();
            } else if (obj.event === 'rwjl') {
                records(data.memberId)
            } else if (obj.event === 'zfb') {
                layer.confirm(
                    '<div style="color: red">转账金额' + data.amount / 100 + '元</div>' + '通过支付宝一键转账给 ' + data.phone + ':' + data.realname, {
                        title: '支付宝一键转账',
                        btn: ['确定转账', '取消'] //可以无限个按钮
                        , btn3: function (index, layero) {
                            //按钮【按钮三】的回调
                            layer.close(index);
                        }
                    }, function (index) {
                        layer.close(index);

                        layer.prompt({
                            formType: 2,
                            value: cashstr.replace("{money}",data.amount / 100),
                            title: '用户收到的转账备注',
                            area: ['300px', '150px'] //自定义文本域宽高
                        }, function (value, index, elem) {
                            transfer(data.id, 1, value);
                            layer.close(index);
                        });


                    });
            } else if (obj.event === 'rgzz') {
                layer.confirm(
                    '<div style="color: red">转账金额' + data.amount / 100 + '元</div>' + '已完成人工转账给' + data.phone + ':' + data.realname, {
                        title: '人工转账',
                        btn: ['确定转账', '取消'] //可以无限个按钮
                        , btn3: function (index, layero) {
                            //按钮【按钮三】的回调
                            layer.close(index);
                        }
                    }, function (index) {
                        layer.close(index);
                        //按钮【按钮二】的回调
                        transfer(data.id, 2, "");
                    });
            } else if (obj.event === 'lsjl') {
                details(data.memberId)
            } else if (obj.event === 'jujue') {
                repulse(data.id);
            }else if (obj.event === 'wx') {
                layer.confirm(
                    '<div style="color: red">转账金额' + data.amount / 100 + '元</div>' + '通过微信一键转账给 ' + data.phone + ':' + data.realname, {
                        title: '微信一键转账',
                        btn: ['确定转账', '取消'] //可以无限个按钮
                        , btn3: function (index, layero) {
                            //按钮【按钮三】的回调
                            layer.close(index);
                        }
                    }, function (index) {
                        layer.close(index);

                        layer.prompt({
                            formType: 2,
                            value: cashstr.replace("{money}",data.amount / 100),
                            title: '用户收到的转账备注',
                            area: ['300px', '150px'] //自定义文本域宽高
                        }, function (value, index, elem) {
                            transfer(data.id, 3, value);
                            layer.close(index);
                        });


                    });

            }else if (obj.event === 'xbls') {
                xbls(data.memberId)
            }
        });
    });

    function transfer(id, payType, value) {
        $("#loadingModal").modal('show');
        $.ajax({
            url: "/applies/staff-pay",    //请求的url地址
            dataType: "json",   //返回格式为json
            async: true,//请求是否异步，默认为异步，这也是ajax重要特性
            data: {id: id, payType: payType, mark: value},    //参数值,键值对
            type: "post",   //请求方式
            beforeSend: function () {
                //请求前的处理
            },
            success: function (req) {
                $("#loadingModal").modal('hide');
                //请求成功时处理
                if (req.success) {

                    layer.msg(req.message, {icon: 1})

                    reload();

                } else {
                    layer.msg(req.message, {icon: 2})
                }
            },
            complete: function () {
                //请求完成的处理
            },
            error: function () {
                $("#loadingModal").modal('hide');
                //请求出错处理
                layer.msg("请重试！若在失败请联系管理员")
            }
        });
    }

    function queryParams(opt) {
        opt.search = $("#search").val();
        opt.order = 'desc';
        return opt;
    };

    var table = null;


    // 通过
    var pass = function (orderId) {
        if (confirm("确定通过？")) {
            $.post("/applies/pass", {
                'orderId': orderId
            }, function (res) {
                if (res.success) {
                    layer.msg(res.message);
                    reload();
                } else {
                    layer.msg(res.message);
                }


            });
        }
    };

    // 拒绝
    var repulse = function (id) {
        layer.prompt({
            formType: 2,
            value: '审核失败',
            title: '确定拒绝？',
            area: ['300px', '150px'] //自定义文本域宽高
        }, function (value, index, elem) {
            $.post("/applies/repulse", {
                'id': id,
                'remark': value
            }, function (res) {
                if (res.success) {
                    layer.msg(res.message);
                    reload();
                } else {
                    layer.msg(res.message);
                }
            });
            layer.close(index);
        });
    };

    // 任务
    var records = function (memberId) {
        var id = 'record_list';
        var title = '任务详情';
        var href = '/member/recordList/' + memberId;
        if (id) {
            window.parent.iw.dialog({
                size: 'lg',
                id: id,
                title: title,
                href: href
            });
        }
    };

    // 流水
    var details = function (memberId) {
        var id = 'trade_list';
        var title = '收支明细';
        var href = '/member/tradeList/' + memberId;
        if (id) {
            window.parent.iw.dialog({
                size: 'lg',
                id: id,
                title: title,
                href: href
            });
        }
    };

    function reload() {
        star = $("#star").val();
        end = $("#end").val();
        tableIns.reload('dataTableId', {
            where: {
                checkStatus: 2
                , startTime: star
                , endTime: end
                , status: 'Empty'
            }
            , page: {
                curr: 1
            }
        });
    }
</script>
</body>
</html>